package net.jacqeush.mini.rpc.handler;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import net.jacqeush.mini.rpc.codec.Decoder;
import net.jacqeush.mini.rpc.codec.Encoder;
import net.jacqeush.mini.rpc.codec.model.Request;
import net.jacqeush.mini.rpc.codec.model.Response;


/**
 * @author Jacquesh
 * @version 1.0
 * @date 2020/10/16 0:00
 */
public class RpcClientInitializer  extends ChannelInitializer {
    @Override
    protected void initChannel(Channel channel) throws Exception {
        ChannelPipeline pl= channel.pipeline();
                 pl
                  /*添加编码器*/
                .addLast(new Encoder(Request.class))
                 /* 其他参数 */
                .addLast(new LengthFieldBasedFrameDecoder(
                        65536, 0,
                        4, 0,
                        0))
                  /*添加解码*/
                .addLast(new Decoder(Response.class))
                 /*添加业务处理的Handler*/
                .addLast(new RpcClientHandler());



    }
}
